package 面向对象.testSeven;

import 面向对象.实验六.Book;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

public class CopyFile3 {
    public static void main(String[] args) throws Exception{
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\Program Files\\JetBrains\\IntelliJ IDEA 2021.2.3\\MyProject_JAVA\\IdeaProjects\\idea-cu\\src\\面向对象\\testSeven\\book2.dat");
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
        ArrayList<Object> arrayList = new ArrayList<>();
        for (int i =1; i <=10; i++){
            Book book = new Book("1"+i,"第"+i+"本书","IY_Jay");
            arrayList.add(book);
            objectOutputStream.flush();
        }
        objectOutputStream.writeObject(arrayList);
        objectOutputStream.close();

        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("D:\\Program Files\\JetBrains\\IntelliJ IDEA 2021.2.3\\MyProject_JAVA\\IdeaProjects\\idea-cu\\src\\面向对象\\testSeven\\book2.dat"));
        Object object = objectInputStream.readObject();

        ObjectOutputStream objectOutputStream1 = new ObjectOutputStream(new FileOutputStream("D:\\Program Files\\JetBrains\\IntelliJ IDEA 2021.2.3\\MyProject_JAVA\\IdeaProjects\\idea-cu\\src\\面向对象\\testSeven\\book3.dat"));
        if (object != null){
            objectOutputStream1.writeObject(object);
            objectOutputStream1.flush();
            objectOutputStream1.close();
            System.out.println(object);
        }
    }
}
